package com.xunfang.controller;

import com.xunfang.bean.Building;
import com.xunfang.bean.Owner;
import com.xunfang.bean.dto.BuildQueryDTO;
import com.xunfang.bean.dto.OwnerQueryDTO;
import com.xunfang.common.Result;
import com.xunfang.service.IBuildingService;
import com.xunfang.service.IOwnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yellow Docter
 * @date 2023 -11-02
 * @desc
 */
@RestController
@RequestMapping("owner")
public class OwnerController {

    @Autowired
    private IOwnerService ownerService;

    @PostMapping("list/{currentPage}/{pageSize}")
    public Result findOwners(@PathVariable Integer currentPage, @PathVariable Integer pageSize, @RequestBody OwnerQueryDTO ownerQueryDTO){
        return Result.ok(ownerService.findOwners(currentPage,pageSize,ownerQueryDTO));
    }

    @GetMapping("{id}")
    public Result findOwnerById(@PathVariable Integer id){
        return Result.ok(ownerService.findOwnerById(id));
    }

    @PostMapping("")
    public Result addOrUpdateOwner(@RequestBody Owner owner){
        return ownerService.addOrUpdateOwner(owner);
    }

    //查询所有
    @GetMapping("list")
    public Result findOwnersList(){
        return Result.ok(ownerService.findOwnersAll());
    }

    @DeleteMapping("{id}")
    public Result findDeleteById(@PathVariable Integer id){
        return Result.ok(ownerService.findDeleteById(id) ? "操作成功":"失败或者数据有引用");
    }

}
